const express = require('express')
const nunjucks = require('nunjucks')
const { join } = require('path')
const Contants = require('./contants')
const { getGlobalConfig } = require('./api/user')

async function bootstrap() {
    const configRes = await getGlobalConfig()
    if (configRes.code === 20000) {
        const data = configRes.data
        Contants.git_http_path = data.git_http_path

        const app = express()
        nunjucks.configure(join(__dirname, 'views'), {
            autoescape: true,
            express: app
        });
        
        app.use('/assets', express.static(__dirname + '/' + 'assets'))
        app.use(require('./router/index'))
        
        
        app.listen(Contants.port, () => {
            console.log(`http://127.0.0.1:${Contants.port}`)
        })
    }
}

bootstrap()
